local frame, inputBox, placeholder, scrollFrame, inviteButton, closeButton

-- 创建主框架
frame = CreateFrame("Frame", "MyAddonFrame", UIParent, "BackdropTemplate")
frame:SetSize(350, 250)
frame:SetPoint("CENTER")
frame:SetBackdrop({
    bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
    edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
    tile = true,
    tileSize = 32,
    edgeSize = 32,
    insets = { left = 8, right = 8, top = 8, bottom = 8 }
})
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:Hide()

-- 🚀 设置框架层级
frame:SetFrameStrata("TOOLTIP") -- 最高层级
frame:SetFrameLevel(100) -- 提高框架显示等级

-- 创建滚动框架
scrollFrame = CreateFrame("ScrollFrame", "MyAddonScrollFrame", frame, "UIPanelScrollFrameTemplate")
scrollFrame:SetSize(310, 175)
scrollFrame:SetPoint("TOP", frame, "TOP", 0, -20)
scrollFrame:SetFrameStrata("TOOLTIP")
scrollFrame:SetFrameLevel(101)

-- 创建输入框
inputBox = CreateFrame("EditBox", "MyAddonInputBox", scrollFrame)
inputBox:SetMultiLine(true)
inputBox:SetSize(310, 175)
inputBox:SetFontObject(GameFontHighlight)
inputBox:SetAutoFocus(false)
inputBox:SetTextInsets(4, 4, 4, 4) -- 设置文字边距
inputBox:SetMaxLetters(1024)
scrollFrame:SetScrollChild(inputBox)

-- 🚀 设置输入框层级
inputBox:SetFrameStrata("TOOLTIP")
inputBox:SetFrameLevel(102)

-- 创建“伪”placeholder
placeholder = inputBox:CreateFontString(nil, "OVERLAY", "GameFontDisable")
placeholder:SetPoint("TOPLEFT", inputBox, "TOPLEFT", 4, -4)
placeholder:SetText("在这里输入内容...")

inputBox:SetScript("OnEditFocusGained", function(self)
    placeholder:Hide()
end)

inputBox:SetScript("OnEditFocusLost", function(self)
    if self:GetText() == "" then
        placeholder:Show()
    end
end)

inputBox:SetScript("OnTextChanged", function(self)
    if self:GetText() == "" then
        placeholder:Show()
    else
        placeholder:Hide()
    end
end)

-- 创建邀请按钮
inviteButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
inviteButton:SetSize(120, 22)
inviteButton:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -20, 20)
inviteButton:SetText("邀请")
inviteButton:SetScript("OnClick", function()
    local text = inputBox:GetText()
    if text ~= "" then
        local list = { strsplit(",", text) }
        for _, entry in ipairs(list) do
            -- print("邀请：" .. entry)
			C_PartyInfo.InviteUnit(entry)
			
			-- 定义绿色颜色代码
			local greenColorCode = "|cff00ff00"
			-- 定义结束颜色代码
			local endColorCode = "|r"
			-- 要发送的消息
			local message = "邀请：" .. entry
			-- 组合带有颜色代码的完整消息
			local fullMessage = greenColorCode .. message .. endColorCode
			-- 将消息添加到聊天框，设置为仅自己可见
			DEFAULT_CHAT_FRAME:AddMessage(fullMessage, 1, 1, 1, true)
        end
    else
        print("输入框为空")
    end
end)

-- 🚀 设置按钮层级
inviteButton:SetFrameStrata("TOOLTIP")
inviteButton:SetFrameLevel(103)

-- 创建关闭按钮
closeButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
closeButton:SetSize(120, 22)
closeButton:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 20, 20)
closeButton:SetText("关闭")
closeButton:SetScript("OnClick", function()
    frame:Hide()
end)

-- 🚀 设置按钮层级
closeButton:SetFrameStrata("TOOLTIP")
closeButton:SetFrameLevel(103)

-- 创建“打开工具”按钮
local openButton = CreateFrame("Button", nil, UIParent, "UIPanelButtonTemplate")
openButton:SetSize(100, 30)
openButton:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 5, 5)
openButton:SetText("邀请玩家")
openButton:SetMovable(true)
openButton:EnableMouse(true)
openButton:RegisterForDrag("LeftButton")
openButton:SetScript("OnDragStart", openButton.StartMoving)
openButton:SetScript("OnDragStop", openButton.StopMovingOrSizing)
openButton:SetScript("OnClick", function()
    if frame:IsShown() then
        frame:Hide()
    else
		inputBox:SetText('')
        frame:Show()
    end
end)

-- 🚀 设置打开按钮的层级
openButton:SetFrameStrata("TOOLTIP")
openButton:SetFrameLevel(104)
